<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
	<!-- 样式文件的引入 -->
	<link rel="stylesheet" type="text/css" href="/comm-work-flow-server/commons/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="/comm-work-flow-server/commons/themes/icon.css">
	<link href="/comm-work-flow-server/commons/css/style.css" rel="stylesheet" type="text/css"/>
	<script id="jquery_183" type="text/javascript" class="library" src="/comm-work-flow-server/commons/js/jquery-1.8.0.min.js"></script>
	<link rel="stylesheet" type="text/css" href="/comm-work-flow-server/commons/css/flow/flow.css">
	<script type="text/javascript" src="/comm-work-flow-server/commons/js/flow/GooFunc.js"></script>
	<script type="text/javascript" src="/comm-work-flow-server/commons/js/flow/flow.js"></script>
	<script type="text/javascript" src="/comm-work-flow-server/commons/js/flow/flow_fn.js"></script>
	<script type="text/javascript" src="/comm-work-flow-server/commons/js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="/comm-work-flow-server/commons/js/flow/json2.js"></script>
	<script type="text/javascript" src="/comm-work-flow-server/commons/js/easyui-lang-zh_CN.js"></script>
		<!-- 开发国际化的引用，主要完成后台信息在前台提示的国际化，一定要放在最后 -->
	<script type="text/javascript">var ctx = '/comm-work-flow-server';var actionExt = "action";var i18n = new Object();</script>
	<script src="/comm-work-flow-server/commons/js/i18n/message_zh_CN.js" type="text/javascript"></script>
<title>工作流设计器</title>
<!--[if lt IE 9]>
<?import namespace="v" implementation="#default#VML" ?>
<![endif]-->
</head>
<body>
<div id="loadDiv" style="text-align: center;margin-top: 120px;">
	<img src="/comm-work-flow-server/commons/images/flow/load.gif" alt="数据加载中..." />
</div>
<div id="flowBody" style="display: none;">
<div id="flow"></div>
<div style="z-index: 999;display: none;position:absolute;" id="task" class="GooFlow"><b class='ico_task'/></div>
<div style="z-index: 999;display: none;position:absolute;" id="join" class="GooFlow"><b class='ico_join'/></div>
	<div id="joinSelect" class="easyui-dialog" title="分支选择" style="width:500px;height:280px;padding:2px;left: 100px;top: 100px;"
			data-options="
				iconCls: 'icon-save',
				closable: false,
				modal : true,
				buttons: [{
					text:'确定',
					iconCls:'icon-ok',
					handler:function(){
						if(accept()){
							flowResultDir();
							$('#joinSelect').dialog('close');
						}
					}
				}]
			">
			<table id="exeResult" class="easyui-datagrid" style="width:482px;height:auto"
					data-options="
						iconCls: 'icon-edit',
						singleSelect: true,
						toolbar: '#tb',
						onClickRow: onClickRow
					">
				<thead>
					<tr>
						<th data-options="field:'handleResult',width:120,editor:{type:'validatebox',options:{required:true}}">处理结果</th>
						<th data-options="field:'handleResultValue',width:120,align:'right',editor:{type:'validatebox',options:{required:true}}">处理结果值</th>
						<th data-options="field:'toNode',width:236,
						formatter:function(value,row){
							return row.nodeName;
						},
						editor:{
							type:'combobox',
							options:{
								editable:false,
								valueField:'toNode',
								textField:'nodeName',
								required:true
							}
						}">对应下一个节点</th>
					</tr>
				</thead>
			</table>
	</div>
	<div id="tb" style="height:auto">
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="append()">添加</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="removeConditionData()">删除</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="accept()">确定数据</a>
	</div>
	<form action="/comm-work-flow-server/workflow/workflowinfo/save" method="post" id="flowSubmit" style="display: none;">
		<input type="hidden" name="workFlowName"/>
		<input type="hidden" name="workFlowCode"/>
		<input type="hidden" name="sysCode" id="sysCode"/>
		<input type="hidden" id="workflowId" name="id" value=""/>
	</form>
	</div>
	<div id="nodeUserListDialog"></div>
</body>
	<script type="text/javascript">
		var property={
			width:790,
			height:426,
			toolBtns:["task","node"],
			haveHead:true,
			headBtns:["save"],//如果haveHead=true，则定义HEAD区的按钮
			haveTool:true,
			isReDraw:false,
			useOperStack:true,
			workFlowName:'',
			ctx : '/comm-work-flow-server',
			flowId : ''
		};
		var flow,resultData={};
		$(document).ready(function(){
			var workFlowId = getUrlParamValue("workFlowId");
			if (workFlowId != '') {
				$.ajax({
					type: "get",
					async:false,
					timeout:20000,
					url:  '/comm-work-flow-server/workflow/workflowinfo/workFlowById/' + workFlowId,
					success: function(data,res){
						if(data.success == true){
							property.workFlowName=data.data.workFlowName;
							property.flowId = data.data.id;
							property.isReDraw = true;
							$('#workflowId').val(data.data.id);
							$('#sysCode').val(data.data.sysCode);
							flow=$.createGooFlow($("#flow"),property);
							flow.loadData($.parseJSON(data.data.workFlowCode));
						}else{
							$.messager.alert('提示',data.errorMsg,'error');
						}
					},
					error: function(res){
						$.messager.alert('提示','调用接口出现了异常！','error');
					}
				});
			} else {
				flow=$.createGooFlow($("#flow"),property);
				var sysCode = getUrlParamValue('sysCode');
				$('#sysCode').val(sysCode);
			}
			flow.setNodeRemarks(remark);
			$("#dlg").dialog('close');
			$("#joinSelect").dialog('close');
			$('#loadDiv').hide();
			$('#flowBody').show();
		});
		
		function getUrlParamValue(paramName) {
			var url = location.href;
			var params = url.replace("?","?&").split("&");
			for(var i=1;i<params.length;i++) {
				if (params[i].indexOf(paramName+"=") == 0) {
					return params[i].substring((paramName+"=").length,params[i].length);
				}
			}
		}
		
		function openNewFlow(code){
			alert("打开一个新的流程图");
		}
		function openNodeUserListDialog(){
			$('#nodeUserListDialog').dialog({    
			    title:'节点人员选择列表',  
			    iconCls:'icon-list',
			    width: 550,    
			    height: 400,    
			    closed: false,    
			    inline : false,
			    cache: false,    
			    href: 'draw-work-flow-node-users.html',    
			    modal: true,
			    onClose:function(){
					if(flow.$nodeData[nodeId].name==''){
						flow.delNode(nodeId,true);
					}
				},
			    buttons : [{text:'确定',
						iconCls:'icon-ok',
						handler:function(){
							var approveNodeName = $('#approveNodeName').val();
							if($.trim(approveNodeName) == ''){
								$.messager.alert('提示','节点名称不能为空！','info');
							} else {
								var data = $('#userListTable').datagrid('getData');
								var rows = data.rows;
								if(rows.length == 0){
									$.messager.alert('提示','请选择审批用户！','info');
								}else{
									var approveLimit = $('#approveLimit').val();
									if($.trim(approveLimit)){
										var re = /^[0-9]+$/;
										if(!re.test(approveLimit)){
											$.messager.alert('提示','输入的审批期限不是数值类型，请重新输入！','info');
											return;
										}else{
											flow.$nodeData[nodeId].approveLimit = parseInt(approveLimit);
										}
									}
									flow.$nodeData[nodeId].name = approveNodeName;
									$('#'+nodeId+'_name').text(approveNodeName);
									flow.$nodeData[nodeId].approvers = rows;
									if($('#composition')[0].checked){
										flow.$nodeData[nodeId].selMethod = $('#composition')[0].value;
									}else{
										flow.$nodeData[nodeId].selMethod = $('#aggregation')[0].value;
									}
									$('#nodeUserListDialog').dialog('close');
								}
							}
						}
					},{
						text:'取消',
						iconCls:'icon-cancel',
						handler:function(){
							$('#nodeUserListDialog').dialog('close');
						}}]
			});
		}
	</script>
</html>
